package com.ruoyi.web.controller.airplane;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbDownloadToken;
import com.ruoyi.system.service.ITbDownloadTokenService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 下载令牌Controller
 *
 * @author ruoyi
 * @date 2025-09-01
 */
@RestController
@RequestMapping("/system/token")
public class TbDownloadTokenController extends BaseController {
    @Autowired
    private ITbDownloadTokenService tbDownloadTokenService;

    /**
     * 查询下载令牌列表
     */
   // @PreAuthorize("@ss.hasPermi('system:token:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbDownloadToken tbDownloadToken) {
        startPage();
        List<TbDownloadToken> list = tbDownloadTokenService.selectTbDownloadTokenList(tbDownloadToken);
        return getDataTable(list);
    }

    /**
     * 导出下载令牌列表
     */
   // @PreAuthorize("@ss.hasPermi('system:token:export')")
    @Log(title = "下载令牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDownloadToken tbDownloadToken) {
        List<TbDownloadToken> list = tbDownloadTokenService.selectTbDownloadTokenList(tbDownloadToken);
        ExcelUtil<TbDownloadToken> util = new ExcelUtil<TbDownloadToken>(TbDownloadToken.class);
        util.exportExcel(response, list, "下载令牌数据");
    }

    /**
     * 获取下载令牌详细信息
     */
   // @PreAuthorize("@ss.hasPermi('system:token:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tbDownloadTokenService.selectTbDownloadTokenById(id));
    }

    /**
     * 新增下载令牌
     */
   // @PreAuthorize("@ss.hasPermi('system:token:add')")
    @Log(title = "下载令牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbDownloadToken tbDownloadToken) {
        return toAjax(tbDownloadTokenService.insertTbDownloadToken(tbDownloadToken));
    }

    /**
     * 修改下载令牌
     */
  //  @PreAuthorize("@ss.hasPermi('system:token:edit')")
    @Log(title = "下载令牌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDownloadToken tbDownloadToken) {
        return toAjax(tbDownloadTokenService.updateTbDownloadToken(tbDownloadToken));
    }

    /**
     * 删除下载令牌
     */
   // @PreAuthorize("@ss.hasPermi('system:token:remove')")
    @Log(title = "下载令牌", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbDownloadTokenService.deleteTbDownloadTokenByIds(ids));
    }
}
